#ifndef FINDSCUTHREAD_H
#define FINDSCUTHREAD_H

#include "dcmtk/dcmnet/dfindscu.h"
class ImportStudyModel;

class FindSCUCallback: public DcmFindSCUCallback
{
public:
    FindSCUCallback(ImportStudyModel *model):
        studyModel(model),
        abort(false),
        DcmFindSCUCallback(){}

    void callback(T_DIMSE_C_FindRQ *request,
                  int responseCount,
                  T_DIMSE_C_FindRSP *rsp,
                  DcmDataset *responseIdentifiers);

    void setAbort() { abort = true; }

private:
    volatile bool abort;
    ImportStudyModel *studyModel;
};

#include <QThread>
#include <QDate>
#include "../share/dicomscp.h"
#include "dcmtk/dcmnet/assoc.h"
#include "dcmtk/dcmnet/dimse.h"
class FindSCUCallback;
class DcmDataset;
class DcmFileFormat;



class FindSCUThread : public QThread
{
    Q_OBJECT
public:
    explicit FindSCUThread(ImportStudyModel *model, QObject *parent = 0):
        callback_(new FindSCUCallback(model)),QThread(parent){}
    ~FindSCUThread() { delete callback_; }
    void setAbort() { callback_->setAbort(); }

    void run();
    void setQRScp(const DicomScp &scp) { qrscp = scp; }
    void setPatientId(const QString &id) { patientId = id; }
    void setPatientName(const QString &name) { patientName = name; }
    void setAccNumber(const QString &accNum) { accNumber = accNum; }
    void setModality(const QString &modality) { this->modality = modality; }
    void setFromDateTime(const QDateTime &time) { fromTime = time; }
    void setToDateTime(const QDateTime &time) { toTime = time; }

signals:
    void progressMsg(const QString &msg);

public slots:

private:
    OFCondition findSCU(T_ASC_Association * assoc, DcmDataset *keys);

    FindSCUCallback *callback_;
    DicomScp qrscp;
    QString patientId;
    QString patientName;
    QString accNumber;
    QString modality;
    QDateTime fromTime;
    QDateTime toTime;
};

#endif // FINDSCUTHREAD_H
